package cn.shoukaiseki.sjf4j.log;

import cn.shoukaiseki.sjf4j.node.TreeNode;
import com.fasterxml.jackson.databind.JsonNode;
import com.google.common.collect.Lists;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;

public abstract class BaseLog<T> {

    StringBuffer sb=new StringBuffer();



    /**
     * Sjf4jLog,JacksonLog 中该方法存储到 sb 的信息要保持一致,因为最终需要equals校验两个输出结果
     * @param key
     * @param jsonNode
     */
    public abstract void printNodeInfo(String key, T jsonNode);

    public String getLogString(){
        return sb.toString();
    }

    public static String keyJoin(String parentKey,String key){
        if (parentKey==null||parentKey.isEmpty()) {
            return key;
        }
        return parentKey+"."+key;
    }

    public static String keyJoin(String parentKey,int key){
        if (parentKey==null||parentKey.isEmpty()) {
            return "["+key+"]";
        }
        return parentKey+"["+key+"]";
    }

    public Iterator<String> sort(Iterator<String> fieldNames){
        ArrayList<String> list = Lists.newArrayList(fieldNames);
        Collections.sort(list);
        return list.iterator();
    }
}
